<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <el-row>
          <el-col :span="8">
            <el-input
              placeholder="请输入查询内容"
              size="normal"
              clearable
              v-model="queryInfo.query"
            ></el-input>
          </el-col>

          <el-col :span="16">
            <el-button size="default" icon="el-icon-search" @click="getOrderList"></el-button>
          </el-col>

          <el-table stripe style="width: 100%" :data="orderList">
            <el-table-column type="index" label="#"> </el-table-column>
            <el-table-column prop="order_price" label="订单价格" width="180">
            </el-table-column>
            <el-table-column prop="order_number" label="订单编号" width="180">
            </el-table-column>
            <el-table-column prop="pay_status" label="是否付款" width="180">
              <template slot-scope="scope">
                <el-tag type="danger" v-if="scope.row.pay_status == '0'"
                  >未付款</el-tag
                >
                <el-tag type="success" v-else>已付款</el-tag>
              </template>
            </el-table-column>
            <el-table-column prop="is_send" label="是否发票"> </el-table-column>
            <el-table-column prop="create_time" label="下单时间">
              <template slot-scope="scope">
                {{ (scope.row.create_time * 1000) | dateFormat("") }}
              </template>
            </el-table-column>
            <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button
                type="primary"
                size="default"
                icon="el-icon-edit"
                @click="showOrderEdit(scope.row.order_id)"
              ></el-button>
              <el-button
                type="success"
                size="default"
                icon="el-icon-location-outline"
                @click="showProgressDialog"
              ></el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-row>
      </div>
      <!-- 分页 -->
      <div class="block">
        <span class="demonstration">完整功能</span>
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryInfo.pagenum"
          :page-sizes="[5, 10, 20, 50]"
          :page-size="queryInfo.pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </el-card>

    <!-- 订单管理操作dialog -->
    <el-dialog
      title="修改地址"
      :visible.sync="OrderEditdialogVisible"
      width="30%"
    @close="closeDialog"
    >
      <el-form
        :model="addressForm"
        :rules="OrderEditRules"
        ref="OrderEditRuleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="活动名称" prop="address">
          <el-cascader
            :options="cityOptions"
            v-model="addressForm.address"
            clearable
            filterable
            :show-all-levels="false"
            :props="{
              expandTrigger: 'hover',
            }">
          </el-cascader>
        </el-form-item>

<el-form-item label="详细地址" prop="addressDetail">
    <el-input v-model="addressForm.addressDetail"></el-input>
  </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="OrderEditdialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="orderEdit"
          >确 定</el-button
        >
      </span>
    </el-dialog>

<el-dialog
  title="物流进度"
  :visible.sync="progressVisible"
  width="30%">

<el-timeline reverse="true">
    <el-timeline-item
      v-for="(activity, index) in progressInfo"
      :key="index"
      :timestamp="activity.time">
      {{activity.context}}

    </el-timeline-item>
  </el-timeline>

  <span slot="footer" class="dialog-footer">
    <el-button @click="progressVisible = false">取 消</el-button>
    <el-button type="primary" @click="progressVisible = false">确 定</el-button>
  </span>
</el-dialog>
  
  
    
  </div>
</template>

<script>
import cityOptions from "../../assets/js/city_data2017_element.js";
export default {
  data() {
    return {
      orderList: [],

      total: 0,
      queryInfo: {
        query: "",
        pagenum: 1,
        pagesize: 5,
      },
      OrderEditdialogVisible: false,
      cityOptions: cityOptions,//引入的js文件 中国城市数据
      addressForm: {
        address: "",
        addressDetail: "",
      },
      OrderEditRules: {
        address: [{ required: true, message: "请选择地址", trigger: "blur" }],
        addressDetail: [{ required: true, message: "请输入地址", trigger: "blur" },],
      },
      progressInfo:[],
      progressVisible:false,
    };
  },


  methods: {
    //   获取订单列表
    async getOrderList() {
      const { data: res } = await this.$http.get("orders", {
        params: this.queryInfo
      });
      console.log(res);
 
      if (res.meta.status !== 200) {
        return this.$message.error("get请求order数据失败");
      }else{
                this.orderList = res.data.goods;
      this.total = res.data.total;
          return this.$message.success("get请求order数据成功")
      }
    },

    // 切换显示行数
    handleSizeChange(val) {
      this.queryInfo.pagesize = val;
      this.getOrderList();
    },
    // 切换页数
    handleCurrentChange(val) {
      this.queryInfo.pagenum = val;
      this.getOrderList();
    },

// 显示订单编辑Dialog
    async showOrderEdit(id) {
     const {data:res}=  await this.$http.get(`orders/${id}`)
       console.log(res);
       if(res.meta.status!==200){
           return this.$message.error('get查询订单详情失败')
       }
      this.OrderEditdialogVisible = true;
    },

// 关闭订单对Form清空处理
    closeDialog(){
        this.$refs.OrderEditRuleForm.resetFields();
        console.log('orderclose');
    },


// 提交编辑给服务器
    async orderEdit(id) {
      const { data: res } = await this.$http.put(`orders/${id}`);
      if (res.meta.status !== 200) {
        return this.$message.error("put修改地址错误");
      } else {
        this.OrderEditdialogVisible = false;
      }
    },

   async showProgressDialog(){
      const {data:res} = await this.$http.get(`/kuaidi/804909574412544580`)
      console.log(res);
      if (res.meta.status !== 200) {
        return this.$message.error("get请求物流数据失败");
      }else{
        this.progressInfo=res.data;
          this.progressVisible=true;
          return this.$message.success("get请求物流数据成功")
      }
    
    }

 
  },

  created() {
    this.getOrderList();
  },
};
</script>

<style lang="less" scoped></style>